import axios from "axios";
import { Notification } from 'element-ui';
import Vue from "vue";

let action = axios.create({
  baseURL: 'http://localhost:8081',
  timeout: 5000
})

// 请求拦截器
action.interceptors.request.use(res => {
  let token = Vue.ls.get("token");
  res.headers.Authorization = token;
  return res;
})

//设置响应拦截器
action.interceptors.response.use(res => {
  if (res.status == 200) {
    return res.data;
  } else if (res.status == 500) {
    this.$notify.error({
      title: '接口异常',
      message: '请联系管理员！'
    });
  }

}, error => {
  Notification.error({
    title: '接口异常',
    // message: '请联系管理员！'
    message: error
  });
  // return Promise.reject(error);
});

export function getAction(url, params) {
  return action({
    url: url,
    method: 'get',
    params: params,
  });
};

export function postAction(url, params) {
  return action({
    url: url,
    method: 'post',
    data: params,
  });
};




